package com.jiang.vo;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;

public class Student implements Delayed {

	private String name;
	private long doseg; // 学生做题的时间段
	private long subtime; // 学生做题提交的时间点

	public Student(String name, long doseg, TimeUnit unit) {
		this.name = name;
		this.doseg = TimeUnit.MILLISECONDS.convert(doseg, unit); // 统一转换为毫秒
		this.subtime = System.currentTimeMillis() + this.doseg;
	}

	// 出队列优先级
	@Override
	public int compareTo(Delayed o) {

		return (int) (this.doseg - getDelay(TimeUnit.MILLISECONDS));

	}

	@Override
	public long getDelay(TimeUnit unit) {

		return unit.convert(subtime - System.currentTimeMillis(), TimeUnit.MILLISECONDS);
	}
	
	@Override
	public String toString() {
		return "我是学生"+name+"，我作答的时间是"+TimeUnit.SECONDS.convert(this.doseg, TimeUnit.MILLISECONDS)+"秒,交卷时间-->"+new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date(subtime));
	}

}
